package com.guiwu.controller;

import com.guiwu.entity.Category;
import com.guiwu.entity.User;
import com.guiwu.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 获取当前用户可见的所有分类（系统+自定义）
     */
    @GetMapping("/list")
    public List<Category> list(@AuthenticationPrincipal User user) {
        return categoryService.getAllCategoriesForUser(user.getId());
    }

    /**
     * 新增自定义分类
     */
    @PostMapping("/add")
    public boolean add(@AuthenticationPrincipal User user, @RequestParam String name) {
        return categoryService.addUserCategory(user.getId(), name);
    }

    /**
     * 删除自定义分类
     */
    @PostMapping("/delete")
    public boolean delete(@AuthenticationPrincipal User user, @RequestParam Long categoryId) {
        return categoryService.deleteUserCategory(user.getId(), categoryId);
    }
} 